package com.sunlands.qdcy.tongzhuo.vo;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sunlands.qdcy.tongzhuo.model.UserDiaryForwardDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.Objects;


/**
 * Created with meng.
 * User: meng5
 * Date: 2019-06-24
 * Description:
 */

@Data
@JsonSerialize
@ApiModel(value = "转发信息")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ForwardVO {

    @ApiModelProperty(value = "[不填]id")
    private Long id;

    @ApiModelProperty(value = "[必填]1:日记，3:回复")
    private Integer type;

    @ApiModelProperty(value = "[必填]对象id，当type=1时，是日记id;当type=3时，是评论id")
    private Long targetId;

    @ApiModelProperty(value = "[必填]转发用户id")
    private Long fromUserId;

    @ApiModelProperty(value = "[必填]被转发的内容（targetId）的发布用户id")
    private Long targetUserId;

    @ApiModelProperty(value = "[不填]当转发到我的日记时使用，存放转发人的内容")
    private String forwardMessage;

    @ApiModelProperty(value = "[不填]创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "[必填]转发位置：1-站内，2-站外微信，3-我的日记")
    private Integer station;



    public static ForwardVO from(UserDiaryForwardDO userDiaryForward) {
        return Objects.isNull(userDiaryForward) ? null : ForwardVO.builder()
                .id(userDiaryForward.getId())
                .targetId(userDiaryForward.getTargetId())
                .fromUserId(userDiaryForward.getFromUserId())
                .targetUserId(userDiaryForward.getTargetUserId())
                .createTime(userDiaryForward.getCreateTime())
                .type(userDiaryForward.getType())
                .build();
    }

    public UserDiaryForwardDO record(){

        UserDiaryForwardDO record = new UserDiaryForwardDO();
        record.setFromUserId(fromUserId);
        record.setCreateTime(createTime);
        record.setForwardMessage(forwardMessage);
        record.setStation(station);
        record.setTargetId(targetId);
        record.setTargetUserId(targetUserId);
        record.setType(type);
        return record;
    }

}
